package com.controller;

import com.Dto.CounselorInfoDto;
import com.Dto.GuidanceSessionOfCounselorDto;
import com.common.Result;
import com.pojo.CounselingSession;
import com.service.CounselorService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.List;


@Slf4j
@RestController
@CrossOrigin
@RequestMapping("Counselors")
public class CounselorController {

    @Autowired
    private CounselorService counselorService;

    /**咨询师查询本月排班日期
     *
     * @param userId
     * @return
     */
    @GetMapping("/getCounselorDates")
    public Result<List<LocalDate>> getCounselorDates(@RequestParam("userId") Integer userId){
        Result<List<LocalDate>> listResult = new Result<>();
        try{
            List<LocalDate> dateList = counselorService.getDatesByUserIdAndCurrentMonth(userId);
            listResult.setSuc(dateList);
        }catch (Exception e){
            log.error("获取失败：{}",e.getMessage());
            listResult.setFail("获取失败");
        }
        return listResult;

    }

    /**咨询师查看咨询会话
     *
     * @param userId
     * @return
     */
    @GetMapping("/getCounselorSessions")
    public Result<List<CounselingSession>> getCounselorSessions(@RequestParam("userId") Integer userId){
        Result<List<CounselingSession>> listResult = new Result<>();
        try{
            List<CounselingSession> sessionList = counselorService.getCounselingSessionsByUserId(userId);

            //sessionList.forEach(element -> System.out.println(element));

            listResult.setSuc(sessionList);
        }catch (Exception e){
            log.error("获取失败：{}",e.getMessage());
            listResult.setFail("获取失败");
        }
        return listResult;
    }

    /**咨询师查看求助会话
     *
     * @param userId
     * @return
     */
    @GetMapping("/getGuidanceSessions")
    public Result<List<GuidanceSessionOfCounselorDto>> getGuidanceSessions(@RequestParam("userId") Integer userId){
        Result<List<GuidanceSessionOfCounselorDto>> listResult = new Result<>();
        try{
            List<GuidanceSessionOfCounselorDto> sessionList = counselorService.getGuidanceSessionByUserId(userId);

            listResult.setSuc(sessionList);
        }catch (Exception e){
            log.error("获取失败：{}",e.getMessage());
            listResult.setFail("获取失败");
        }
        return listResult;
    }


    /**咨询师查看个人信息
     *
     * @param userId
     * @return
     */
    @GetMapping("/getCounselorInfo")
    public Result<List<CounselorInfoDto>> getCounselorInfo(@RequestParam("userId") Integer userId){
        Result<List<CounselorInfoDto>> listResult = new Result<>();
        try{
            List<CounselorInfoDto> info = counselorService.getCounselorInfoByUserId(userId);

            listResult.setSuc(info);
        }catch (Exception e){
            log.error("获取失败：{}",e.getMessage());
            listResult.setFail("获取失败");
        }
        return listResult;
    }


}
